function AjaxFun() {
	this.data = '';

}
AjaxFun.prototype.extend=function(destination,params1,params2){
    for(var i=1; i<arguments.length; i++){
    	for(var key in arguments[i]){
            if(arguments[i].hasOwnProperty(key)){
            	 arguments[0][key] = arguments[i][key];
            }
        }   
    } 
    return arguments[0];
};

AjaxFun.prototype.loginpost=function(url,data,params,callback,failCallback,reloginCallback){
	if (plus.networkinfo.getCurrentType() == plus.networkinfo.CONNECTION_NONE) {
		mui.toast("网络异常，请检查网络设置！");
		if(document.querySelector('#pullrefresh')){
			mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
			mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);
		}
		return false;
	}else{
		//获取本地缓存中储存的用户信息
		failCallback=failCallback?failCallback:function(d){d.msg=d.msg?d.msg:'失败';plus.nativeUI.alert(d.msg);};
		callback=callback?callback:function(){};
		reloginCallback=reloginCallback?reloginCallback:function(){
			localStorage.clear();
			openWindow('../../login.html','login');
		}
		mui.ajax(url, {
			dataType: 'json', //服务器返回json格式数据
			type: 'post', //HTTP请求类型
			timeout:10000, //超时时间设置为10秒；
			async: false, //异步设为true
			data:data,
	//		crossDomain:true,
			success: function(d) {
				if(d.status=='login_fail'){
					reloginCallback();
				}else if(d.status=='success'){				 
					callback(d,params); 
				}else{
					failCallback(d);
				}
			},
			error: function(xhr, type, errorThrown) {
				console.log(xhr); console.log(type); console.log(errorThrown);
				/*plus.nativeUI.alert('网络连接异常，请稍后重试');
				if(document.querySelector('#pullrefresh')){
					mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
					mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);
				}
				return false;*/
			}
		});
	}
	
}
AjaxFun.prototype.postFun = function(url,data,params,callback,failCallback,reloginCallback) {
	var users = JSON.parse(localStorage.getItem('$users') || "{}");
	var newData=this.extend({},users,data);
	reloginCallback=reloginCallback?reloginCallback:'';
 	url=url+'?'+parseInt(Math.random()*100000);
	this.loginpost(url,newData,params,callback,failCallback,reloginCallback);
}

AjaxFun.prototype.getFun = function(url,data,params,callback,failCallback,reloginCallback) {
	failCallback=failCallback?failCallback:function(d){plus.nativeUI.alert(d.msg);};
	callback=callback?callback:function(){};
	reloginCallback=reloginCallback?reloginCallback:function(){
		localStorage.clear();
		openWindow('../../login.html','login');
	}
	url=url+'?'+parseInt(Math.random()*100000);
	mui.ajax(url, {
		dataType: 'json', //服务器返回json格式数据
		type: 'get', //HTTP请求类型
		timeout: 10000, //超时时间设置为10秒；
		async: false, //异步设为true
//		crossDomain:true,
		success: function(d) {
			if(d.status=='login_fail'){
				reloginCallback();
			}else if(d.status=='success'){				 
				callback(d,params); 
			}else{
				failCallback(d);
			}
		},
		error: function(xhr, type, errorThrown) {
			console.log(xhr); console.log(type); console.log(errorThrown);
			plus.nativeUI.alert('网络连接异常，请稍后重试');
			if(document.querySelector('#pullrefresh')){
				mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
				mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);
			}
		}
	});
}



var ajaxFun=new AjaxFun();